<!DOCTYPE html><html lang="zh-CN" data-theme="light"><head><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width, initial-scale=1.0,viewport-fit=cover"><title>Mac M1 Pro 深度学习环境搭建 | 啊粥啊周舟の部落阁</title><meta name="author" content="Zhouwy"><meta name="copyright" content="Zhouwy"><meta name="format-detection" content="telephone=no"><meta name="theme-color" content="#ffffff"><meta name="description" content="Mac M1 Pro 深度学习环境搭建一、前言Mac m1 系列芯片并不同与　intel平台的X86建构，而是采用的Arm架构。据库克的说法，在生产力领域（又称：影音制作）可谓是拳打intel，脚踢AMD。但是在对于Arm架构的芯片而言，最大的挑战就是生态，所以许多专业软件都无法原生支持。但是抵不住M1系列芯片强呀。总会有人忍不住入手的。下面就记录下基于MacBook pro 14 (Mac M1">
<meta property="og:type" content="article">
<meta property="og:title" content="Mac M1 Pro 深度学习环境搭建">
<meta property="og:url" content="https://gitee.com/zwyywz/zwyywz.git/2020/09/20/Mac%20M1%20Pro%20%E6%B7%B1%E5%BA%A6%E5%AD%A6%E4%B9%A0%E7%8E%AF%E5%A2%83%E6%90%AD%E5%BB%BA/index.html">
<meta property="og:site_name" content="啊粥啊周舟の部落阁">
<meta property="og:description" content="Mac M1 Pro 深度学习环境搭建一、前言Mac m1 系列芯片并不同与　intel平台的X86建构，而是采用的Arm架构。据库克的说法，在生产力领域（又称：影音制作）可谓是拳打intel，脚踢AMD。但是在对于Arm架构的芯片而言，最大的挑战就是生态，所以许多专业软件都无法原生支持。但是抵不住M1系列芯片强呀。总会有人忍不住入手的。下面就记录下基于MacBook pro 14 (Mac M1">
<meta property="og:locale" content="zh_CN">
<meta property="og:image" content="https://blog-1300216920.cos.ap-nanjing.myqcloud.com/apple-macbook-pro-m1-2020-5-20230410110609763.jpg">
<meta property="article:published_time" content="2020-09-20T01:25:00.000Z">
<meta property="article:modified_time" content="2023-04-10T03:06:20.664Z">
<meta property="article:author" content="Zhouwy">
<meta property="article:tag" content="Macbook pro">
<meta property="article:tag" content="环境配置">
<meta property="article:tag" content="Pytorch">
<meta property="article:tag" content="DeepLearning">
<meta name="twitter:card" content="summary">
<meta name="twitter:image" content="https://blog-1300216920.cos.ap-nanjing.myqcloud.com/apple-macbook-pro-m1-2020-5-20230410110609763.jpg"><link rel="shortcut icon" href="/zwyywz/img/favicon.png"><link rel="canonical" href="https://gitee.com/zwyywz/zwyywz.git/2020/09/20/Mac%20M1%20Pro%20%E6%B7%B1%E5%BA%A6%E5%AD%A6%E4%B9%A0%E7%8E%AF%E5%A2%83%E6%90%AD%E5%BB%BA/index.html"><link rel="preconnect" href="//cdn.jsdelivr.net"/><link rel="preconnect" href="//busuanzi.ibruce.info"/><link rel="stylesheet" href="/zwyywz/css/index.css"><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fortawesome/fontawesome-free/css/all.min.css" media="print" onload="this.media='all'"><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fancyapps/ui/dist/fancybox/fancybox.min.css" media="print" onload="this.media='all'"><script>const GLOBAL_CONFIG = { 
  root: '/zwyywz/',
  algolia: undefined,
  localSearch: undefined,
  translate: {"defaultEncoding":2,"translateDelay":0,"msgToTraditionalChinese":"繁","msgToSimplifiedChinese":"簡"},
  noticeOutdate: undefined,
  highlight: {"plugin":"highlighjs","highlightCopy":true,"highlightLang":true,"highlightHeightLimit":300},
  copy: {
    success: '复制成功',
    error: '复制错误',
    noSupport: '浏览器不支持'
  },
  relativeDate: {
    homepage: true,
    post: true
  },
  runtime: '',
  dateSuffix: {
    just: '刚刚',
    min: '分钟前',
    hour: '小时前',
    day: '天前',
    month: '个月前'
  },
  copyright: {"limitCount":50,"languages":{"author":"作者: Zhouwy","link":"链接: ","source":"来源: 啊粥啊周舟の部落阁","info":"著作权归作者所有。商业转载请联系作者获得授权，非商业转载请注明出处。"}},
  lightbox: 'fancybox',
  Snackbar: undefined,
  source: {
    justifiedGallery: {
      js: 'https://cdn.jsdelivr.net/npm/flickr-justified-gallery/dist/fjGallery.min.js',
      css: 'https://cdn.jsdelivr.net/npm/flickr-justified-gallery/dist/fjGallery.min.css'
    }
  },
  isPhotoFigcaption: false,
  islazyload: false,
  isAnchor: false,
  percent: {
    toc: true,
    rightside: true,
  }
}</script><script id="config-diff">var GLOBAL_CONFIG_SITE = {
  title: 'Mac M1 Pro 深度学习环境搭建',
  isPost: true,
  isHome: false,
  isHighlightShrink: false,
  isToc: true,
  postUpdate: '2023-04-10 11:06:20'
}</script><noscript><style type="text/css">
  #nav {
    opacity: 1
  }
  .justified-gallery img {
    opacity: 1
  }

  #recent-posts time,
  #post-meta time {
    display: inline !important
  }
</style></noscript><script>(win=>{
    win.saveToLocal = {
      set: function setWithExpiry(key, value, ttl) {
        if (ttl === 0) return
        const now = new Date()
        const expiryDay = ttl * 86400000
        const item = {
          value: value,
          expiry: now.getTime() + expiryDay,
        }
        localStorage.setItem(key, JSON.stringify(item))
      },

      get: function getWithExpiry(key) {
        const itemStr = localStorage.getItem(key)

        if (!itemStr) {
          return undefined
        }
        const item = JSON.parse(itemStr)
        const now = new Date()

        if (now.getTime() > item.expiry) {
          localStorage.removeItem(key)
          return undefined
        }
        return item.value
      }
    }
  
    win.getScript = url => new Promise((resolve, reject) => {
      const script = document.createElement('script')
      script.src = url
      script.async = true
      script.onerror = reject
      script.onload = script.onreadystatechange = function() {
        const loadState = this.readyState
        if (loadState && loadState !== 'loaded' && loadState !== 'complete') return
        script.onload = script.onreadystatechange = null
        resolve()
      }
      document.head.appendChild(script)
    })
  
    win.getCSS = (url,id = false) => new Promise((resolve, reject) => {
      const link = document.createElement('link')
      link.rel = 'stylesheet'
      link.href = url
      if (id) link.id = id
      link.onerror = reject
      link.onload = link.onreadystatechange = function() {
        const loadState = this.readyState
        if (loadState && loadState !== 'loaded' && loadState !== 'complete') return
        link.onload = link.onreadystatechange = null
        resolve()
      }
      document.head.appendChild(link)
    })
  
      win.activateDarkMode = function () {
        document.documentElement.setAttribute('data-theme', 'dark')
        if (document.querySelector('meta[name="theme-color"]') !== null) {
          document.querySelector('meta[name="theme-color"]').setAttribute('content', '#0d0d0d')
        }
      }
      win.activateLightMode = function () {
        document.documentElement.setAttribute('data-theme', 'light')
        if (document.querySelector('meta[name="theme-color"]') !== null) {
          document.querySelector('meta[name="theme-color"]').setAttribute('content', '#ffffff')
        }
      }
      const t = saveToLocal.get('theme')
    
          if (t === 'dark') activateDarkMode()
          else if (t === 'light') activateLightMode()
        
      const asideStatus = saveToLocal.get('aside-status')
      if (asideStatus !== undefined) {
        if (asideStatus === 'hide') {
          document.documentElement.classList.add('hide-aside')
        } else {
          document.documentElement.classList.remove('hide-aside')
        }
      }
    
    const detectApple = () => {
      if(/iPad|iPhone|iPod|Macintosh/.test(navigator.userAgent)){
        document.documentElement.classList.add('apple')
      }
    }
    detectApple()
    })(window)</script><link rel="stylesheet" href="///at.alicdn.com/t/c/font_4018630_wl3l75i04vl.css"><meta name="generator" content="Hexo 6.3.0"></head><body><div id="sidebar"><div id="menu-mask"></div><div id="sidebar-menus"><div class="avatar-img is-center"><img src="/zwyywz/img/avatar.png" onerror="onerror=null;src='/img/friend_404.gif'" alt="avatar"/></div><div class="sidebar-site-data site-data is-center"><a href="/zwyywz/archives/"><div class="headline">文章</div><div class="length-num">17</div></a><a href="/zwyywz/tags/"><div class="headline">标签</div><div class="length-num">29</div></a><a href="/zwyywz/categories/"><div class="headline">分类</div><div class="length-num">5</div></a></div><hr/><div class="menus_items"><div class="menus_item"><a class="site-page" href="/zwyywz/"><i class="fa-fw fas fa-home"></i><span> 首页</span></a></div><div class="menus_item"><a class="site-page" href="/zwyywz/archives/"><i class="fa-fw fas fa-archive"></i><span> 时间轴</span></a></div><div class="menus_item"><a class="site-page" href="/zwyywz/tags/"><i class="fa-fw fas fa-tags"></i><span> 标签</span></a></div><div class="menus_item"><a class="site-page group" href="javascript:void(0);"><i class="fa-fw fas fa-list"></i><span> 分类</span><i class="fas fa-chevron-down"></i></a><ul class="menus_item_child"><li><a class="site-page child" href="/zwyywz/note/"><i class="fa-fw iconfont icon-xuexibiji"></i><span> 学习笔记</span></a></li><li><a class="site-page child" href="/zwyywz/opensource/"><i class="fa-fw iconfont icon-xiangmu"></i><span> 开源项目</span></a></li><li><a class="site-page child" href="/zwyywz/development/"><i class="fa-fw iconfont icon-peizhi-xitongpeizhi"></i><span> 环境配置</span></a></li></ul></div><div class="menus_item"><a class="site-page group" href="javascript:void(0);"><i class="fa-fw fas fa-list"></i><span> 清单</span><i class="fas fa-chevron-down"></i></a><ul class="menus_item_child"><li><a class="site-page child" href="/zwyywz/music/"><i class="fa-fw fas fa-music"></i><span> 音乐</span></a></li><li><a class="site-page child" href="/zwyywz/movies/"><i class="fa-fw fas fa-video"></i><span> 电影</span></a></li></ul></div><div class="menus_item"><a class="site-page" href="/zwyywz/link/"><i class="fa-fw fas fa-link"></i><span> 链接</span></a></div><div class="menus_item"><a class="site-page" href="/zwyywz/about/"><i class="fa-fw fas fa-heart"></i><span> 关于</span></a></div></div></div></div><div class="post" id="body-wrap"><header class="post-bg" id="page-header" style="background-image: url('https://blog-1300216920.cos.ap-nanjing.myqcloud.com/apple-macbook-pro-m1-2020-5-20230410110609763.jpg')"><nav id="nav"><span id="blog-info"><a href="/zwyywz/" title="啊粥啊周舟の部落阁"><span class="site-name">啊粥啊周舟の部落阁</span></a></span><div id="menus"><div class="menus_items"><div class="menus_item"><a class="site-page" href="/zwyywz/"><i class="fa-fw fas fa-home"></i><span> 首页</span></a></div><div class="menus_item"><a class="site-page" href="/zwyywz/archives/"><i class="fa-fw fas fa-archive"></i><span> 时间轴</span></a></div><div class="menus_item"><a class="site-page" href="/zwyywz/tags/"><i class="fa-fw fas fa-tags"></i><span> 标签</span></a></div><div class="menus_item"><a class="site-page group" href="javascript:void(0);"><i class="fa-fw fas fa-list"></i><span> 分类</span><i class="fas fa-chevron-down"></i></a><ul class="menus_item_child"><li><a class="site-page child" href="/zwyywz/note/"><i class="fa-fw iconfont icon-xuexibiji"></i><span> 学习笔记</span></a></li><li><a class="site-page child" href="/zwyywz/opensource/"><i class="fa-fw iconfont icon-xiangmu"></i><span> 开源项目</span></a></li><li><a class="site-page child" href="/zwyywz/development/"><i class="fa-fw iconfont icon-peizhi-xitongpeizhi"></i><span> 环境配置</span></a></li></ul></div><div class="menus_item"><a class="site-page group" href="javascript:void(0);"><i class="fa-fw fas fa-list"></i><span> 清单</span><i class="fas fa-chevron-down"></i></a><ul class="menus_item_child"><li><a class="site-page child" href="/zwyywz/music/"><i class="fa-fw fas fa-music"></i><span> 音乐</span></a></li><li><a class="site-page child" href="/zwyywz/movies/"><i class="fa-fw fas fa-video"></i><span> 电影</span></a></li></ul></div><div class="menus_item"><a class="site-page" href="/zwyywz/link/"><i class="fa-fw fas fa-link"></i><span> 链接</span></a></div><div class="menus_item"><a class="site-page" href="/zwyywz/about/"><i class="fa-fw fas fa-heart"></i><span> 关于</span></a></div></div><div id="toggle-menu"><a class="site-page" href="javascript:void(0);"><i class="fas fa-bars fa-fw"></i></a></div></div></nav><div id="post-info"><h1 class="post-title">Mac M1 Pro 深度学习环境搭建</h1><div id="post-meta"><div class="meta-firstline"><span class="post-meta-date"><i class="far fa-calendar-alt fa-fw post-meta-icon"></i><span class="post-meta-label">发表于</span><time class="post-meta-date-created" datetime="2020-09-20T01:25:00.000Z" title="发表于 2020-09-20 09:25:00">2020-09-20</time><span class="post-meta-separator">|</span><i class="fas fa-history fa-fw post-meta-icon"></i><span class="post-meta-label">更新于</span><time class="post-meta-date-updated" datetime="2023-04-10T03:06:20.664Z" title="更新于 2023-04-10 11:06:20">2023-04-10</time></span></div><div class="meta-secondline"><span class="post-meta-separator">|</span><span class="post-meta-pv-cv" id="" data-flag-title="Mac M1 Pro 深度学习环境搭建"><i class="far fa-eye fa-fw post-meta-icon"></i><span class="post-meta-label">阅读量:</span><span id="busuanzi_value_page_pv"><i class="fa-solid fa-spinner fa-spin"></i></span></span></div></div></div></header><main class="layout" id="content-inner"><div id="post"><article class="post-content" id="article-container"><h1 id="Mac-M1-Pro-深度学习环境搭建"><a href="#Mac-M1-Pro-深度学习环境搭建" class="headerlink" title="Mac M1 Pro 深度学习环境搭建"></a>Mac M1 Pro 深度学习环境搭建</h1><h2 id="一、前言"><a href="#一、前言" class="headerlink" title="一、前言"></a>一、前言</h2><p>Mac m1 系列芯片并不同与　intel平台的X86建构，而是采用的Arm架构。据库克的说法，在生产力领域（又称：影音制作）可谓是拳打intel，脚踢AMD。但是在对于Arm架构的芯片而言，最大的挑战就是生态，所以许多专业软件都无法原生支持。但是抵不住M1系列芯片强呀。总会有人忍不住入手的。下面就记录下基于MacBook pro 14 (Mac M1 Pro)的深度学习环境搭建过程。</p>
<p>基本上常用的开发工具如下图所示：</p>
<p><img src="https://blog-1300216920.cos.ap-nanjing.myqcloud.com/python%E6%B7%B1%E5%BA%A6%E5%AD%A6%E4%B9%A0.png" alt=""></p>
<h2 id="二、基础环境"><a href="#二、基础环境" class="headerlink" title="二、基础环境"></a>二、基础环境</h2><p>到目前为止，anaconda还不能原生支持M1芯片，而Python是已经原生支持M1芯片了。故而这里采用另一种方式安装Python。</p>
<ul>
<li><em>下载 <a href="https://link.zhihu.com/?target=https%3A//codechina.csdn.net/mirrors/conda-forge/miniforge%3Futm_source%3Dcsdn_github_accelerator">Miniforge3</a> 点开链接找到对应的版本，下载.sh文件：</em></li>
</ul>
<p><img src="https://blog-1300216920.cos.ap-nanjing.myqcloud.com/20211101.png" alt="20211101"></p>
<p>在命令行中，执行该脚本：</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">bash Miniforge3-MacOSX-arm64.sh</span><br></pre></td></tr></table></figure>
<p>之后添加环境变量(一般会自动添加)：</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br></pre></td><td class="code"><pre><span class="line"># &gt;&gt;&gt; conda initialize &gt;&gt;&gt;</span><br><span class="line"># !! Contents within this block are managed by &#x27;conda init&#x27; !!</span><br><span class="line"> __conda_setup=&quot;$(&#x27;/Users/zwy/miniforge3/bin/conda&#x27; &#x27;shell.zsh&#x27; &#x27;hook&#x27; 2&gt; /de    v/null)&quot;</span><br><span class="line">if [ $? -eq 0 ]; then</span><br><span class="line">     eval &quot;$__conda_setup&quot;</span><br><span class="line">else</span><br><span class="line">     if [ -f &quot;/Users/zwy/miniforge3/etc/profile.d/conda.sh&quot; ]; then</span><br><span class="line">         . &quot;/Users/zwy/miniforge3/etc/profile.d/conda.sh&quot;</span><br><span class="line">     else</span><br><span class="line">         export PATH=&quot;/Users/zwy/miniforge3/bin:$PATH&quot;</span><br><span class="line">     fi</span><br><span class="line">fi</span><br><span class="line">unset __conda_setup</span><br></pre></td></tr></table></figure>
<p>之后，终端中会出现（base）环境：即表示成功！</p>
<p><img src="https://blog-1300216920.cos.ap-nanjing.myqcloud.com/20211101%2013.42.32.png" alt=""></p>
<p>然后创建python3.9的虚拟环境：</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">conda create -n YourEnvName python=3.9 #创建</span><br><span class="line">conda activate YourEnvName #激活</span><br></pre></td></tr></table></figure>
<p>基础的开发环境即安装完成：</p>
<h2 id="三、相关的第三库"><a href="#三、相关的第三库" class="headerlink" title="三、相关的第三库"></a>三、相关的第三库</h2><p>首先，是做数据分析的常见库，比如：<code>numpy</code>,<code>matplotlib</code>,<code>pandas</code>····等。暂时不急，优先确定深度学习框架，在安装基础库。因为在安装框架时，会安装对应的基础库，如果自己提前装了，有可能会出现版本不兼容问题。</p>
<p>首先：<code>TensorFlow</code></p>
<p>现如今，<code>TensorFlow</code>已经原生支持Mac M1系列芯片，直接在命令行里面就可以安装：</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">conda install -c apple tensorflow-deps</span><br><span class="line">python -m pip install tensorflow-macos</span><br><span class="line">python -m pip install tensorflow-metal</span><br></pre></td></tr></table></figure>
<p><img src="https://blog-1300216920.cos.ap-nanjing.myqcloud.com/2021-11-03%2014.00.13.png" alt="2021-11-03 14.00.13"></p>
<p>在终端打开python，测试GPU是否可以：</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">import</span> tensorflow <span class="keyword">as</span> tf</span><br><span class="line">tf.test.is_gpu_available()</span><br><span class="line"><span class="comment">#会有警告，但是会返回 True</span></span><br></pre></td></tr></table></figure>
<p><code>TensorFlow</code>安装基本完成！！！</p>
<p>再安装<code>PyTorch</code>:</p>
<p>可以在<a target="_blank" rel="noopener" href="https://anaconda.org/">Anaconda 的网站</a>上找到原生 PyTorch 包</p>
<p><img src="https://blog-1300216920.cos.ap-nanjing.myqcloud.com/%E6%88%AA%E5%B1%8F2021-11-03%2014.06.24.png" alt=""></p>
<p>选择<code>osx-arm64</code>的版本，这里推荐<code>pytorch 1.10.0</code>,执行如下指令即可：</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">conda install -c pytorch pytorch</span><br></pre></td></tr></table></figure>
<p> 最后，先使用<code>pip list</code>查看一下已安装的库，再补上其他必须的库：</p>
<p>我再安装了<code>OpenCV</code>,<code>matplotlib</code>,<code>pandas</code>等，可视自己情况再安装</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">conda install  matplotlib pandas</span><br></pre></td></tr></table></figure>
<p>在安装<code>OpenCV</code>过程中发现由于：<code>OpenCV</code>所需的<code>numpy</code>版本是<code>1.21.0</code>以上，而<code>TensorFlow</code>要求的<code>numpy</code>小于<code>1.19.5</code>。</p>
<p>故而不能使用<code>pip</code>    和<code>conda</code>    安装<code>OpenCV</code>。</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">#错误方式</span><br><span class="line">pip install opencv-python</span><br><span class="line">conda install opencv-python</span><br></pre></td></tr></table></figure>
<p><strong>采用编译源码的方式安装<code>OpenCV</code></strong></p>
<ul>
<li><p>1、安装<code>camke</code>:</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">brew install camke</span><br></pre></td></tr></table></figure>
</li>
<li><p>2、获取<code>OpenCV</code><a target="_blank" rel="noopener" href="https://github.com/opencv/opencv_contrib/tree/4.5.4">源码</a>，可以访问<code>Github</code>主页，也可以使用以下命令下载：</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">git clone https://github.com/opencv/opencv_contrib.git</span><br><span class="line">git clone https://github.com/opencv/opencv.git</span><br></pre></td></tr></table></figure>
</li>
<li><p>3、在<code>opencv-4.5.4</code>新建<code>build</code>文件夹，准备编译:</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">mkdir build &amp;&amp; cd build</span><br></pre></td></tr></table></figure>
</li>
<li></li>
<li><p>4、设置<code>camke</code>编译规则，正式编译：</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br></pre></td><td class="code"><pre><span class="line">cmake \</span><br><span class="line">-D CMAKE_SYSTEM_PROCESSOR=arm64 \</span><br><span class="line">-D CMAKE_OSX_ARCHITECTURES=arm64 \</span><br><span class="line">-D WITH_OPENJPEG=OFF \</span><br><span class="line">-D WITH_IPP=OFF \</span><br><span class="line">-D CMAKE_BUILD_TYPE=RELEASE \</span><br><span class="line">-D CMAKE_INSTALL_PREFIX=/usr/local \</span><br><span class="line">-D OPENCV_EXTRA_MODULES_PATH=/YourPath/opencv_contrib-4.5.4/modules \</span><br><span class="line">-D PYTHON3_EXECUTABLE=/YourPath/miniforge3/envs/DeepLearning/bin/python \</span><br><span class="line">-D BUILD_opencv_python2=OFF \</span><br><span class="line">-D BUILD_opencv_python3=ON \</span><br><span class="line">-D INSTALL_PYTHON_EXAMPLES=ON \</span><br><span class="line">-D INSTALL_C_EXAMPLES=OFF \</span><br><span class="line">-D OPENCV_ENABLE_NONFREE=ON \</span><br><span class="line">-D BUILD_EXAMPLES=ON …</span><br></pre></td></tr></table></figure>
<p>完成后，就可以编译了：</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">sudo make -j8</span><br></pre></td></tr></table></figure>
<p>震惊！ 真的快，只有几分钟就编译完了。编译过程中会占满核心！</p>
<p>然后安装：</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">sudo make install</span><br></pre></td></tr></table></figure>
<p>将<code>MacOS</code>的 <code>OpenCV</code>符号链接到虚拟环境:</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">mdfind cv2.cpython</span><br></pre></td></tr></table></figure>
<p><img src="https://blog-1300216920.cos.ap-nanjing.myqcloud.com/2021-11-03%2021.37.48.png" alt=""></p>
<p>最后，再设置软链接：</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">cd /YourPath/miniforge3/envs/YourEnv/lib/python3.9/site-packages</span><br><span class="line">sudo ln -s /YourPath/site-packages/cv2/python-3.8/cv2.cpython-38-darwin.so //cv2.so</span><br></pre></td></tr></table></figure>
<p>大功告成！！！</p>
</li>
</ul>
<h2 id="四、开发工具"><a href="#四、开发工具" class="headerlink" title="四、开发工具"></a>四、开发工具</h2><p><code>Python</code>开发工具有很多，比较常用的当属<code>Pycharm</code>、<code>jupyter notebook</code>和<code>vscode</code>等。这些基本上都已经原生支持Mac M1系列芯片了。</p>
<p>就以<code>Pycharm</code>为例：</p>
<p><img src="https://blog-1300216920.cos.ap-nanjing.myqcloud.com/%E6%88%AA%E5%B1%8F2021-11-03%2022.16.10.png" alt=""></p>
<p>基本配置完成！</p>
<h2 id="五、其他工具"><a href="#五、其他工具" class="headerlink" title="五、其他工具"></a>五、其他工具</h2><p>更新ing·······</p>
</article><div class="post-copyright"><div class="post-copyright__author"><span class="post-copyright-meta">文章作者: </span><span class="post-copyright-info"><a href="https://gitee.com/zwyywz/zwyywz.git">Zhouwy</a></span></div><div class="post-copyright__type"><span class="post-copyright-meta">文章链接: </span><span class="post-copyright-info"><a href="https://gitee.com/zwyywz/zwyywz.git/2020/09/20/Mac%20M1%20Pro%20%E6%B7%B1%E5%BA%A6%E5%AD%A6%E4%B9%A0%E7%8E%AF%E5%A2%83%E6%90%AD%E5%BB%BA/">https://gitee.com/zwyywz/zwyywz.git/2020/09/20/Mac%20M1%20Pro%20%E6%B7%B1%E5%BA%A6%E5%AD%A6%E4%B9%A0%E7%8E%AF%E5%A2%83%E6%90%AD%E5%BB%BA/</a></span></div><div class="post-copyright__notice"><span class="post-copyright-meta">版权声明: </span><span class="post-copyright-info">本博客所有文章除特别声明外，均采用 <a href="https://creativecommons.org/licenses/by-nc-sa/4.0/" target="_blank">CC BY-NC-SA 4.0</a> 许可协议。转载请注明来自 <a href="https://gitee.com/zwyywz/zwyywz.git" target="_blank">啊粥啊周舟の部落阁</a>！</span></div></div><div class="tag_share"><div class="post-meta__tag-list"><a class="post-meta__tags" href="/zwyywz/tags/Macbook-pro/">Macbook pro</a><a class="post-meta__tags" href="/zwyywz/tags/%E7%8E%AF%E5%A2%83%E9%85%8D%E7%BD%AE/">环境配置</a><a class="post-meta__tags" href="/zwyywz/tags/Pytorch/">Pytorch</a><a class="post-meta__tags" href="/zwyywz/tags/DeepLearning/">DeepLearning</a></div><div class="post_share"><div class="social-share" data-image="https://blog-1300216920.cos.ap-nanjing.myqcloud.com/apple-macbook-pro-m1-2020-5-20230410110609763.jpg" data-sites="facebook,twitter,wechat,weibo,qq"></div><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/butterfly-extsrc/sharejs/dist/css/share.min.css" media="print" onload="this.media='all'"><script src="https://cdn.jsdelivr.net/npm/butterfly-extsrc/sharejs/dist/js/social-share.min.js" defer></script></div></div><div class="post-reward"><div class="reward-button"><i class="fas fa-qrcode"></i> 打赏</div><div class="reward-main"><ul class="reward-all"><li class="reward-item"><a href="/zwyywz/img/wechat.jpg" target="_blank"><img class="post-qr-code-img" src="/zwyywz/img/wechat.jpg" alt="微信"/></a><div class="post-qr-code-desc">微信</div></li><li class="reward-item"><a href="/zwyywz/img/alipay.jpg" target="_blank"><img class="post-qr-code-img" src="/zwyywz/img/alipay.jpg" alt="支付宝"/></a><div class="post-qr-code-desc">支付宝</div></li></ul></div></div><nav class="pagination-post" id="pagination"><div class="prev-post pull-left"><a href="/zwyywz/2021/03/26/DataStructAndAlgorithms/" title="数据结构与算法(C/C++实现)"><img class="cover" src="https://blog-1300216920.cos.ap-nanjing.myqcloud.com/数据结构与算法.jpg" onerror="onerror=null;src='/zwyywz/img/404.jpg'" alt="cover of previous post"><div class="pagination-info"><div class="label">上一篇</div><div class="prev_info">数据结构与算法(C/C++实现)</div></div></a></div><div class="next-post pull-right"><a href="/zwyywz/2020/04/26/DigitalImageProcessing/" title="数字图像处理（DIP）"><img class="cover" src="https://blog-1300216920.cos.ap-nanjing.myqcloud.com/DIP.png" onerror="onerror=null;src='/zwyywz/img/404.jpg'" alt="cover of next post"><div class="pagination-info"><div class="label">下一篇</div><div class="next_info">数字图像处理（DIP）</div></div></a></div></nav><div class="relatedPosts"><div class="headline"><i class="fas fa-thumbs-up fa-fw"></i><span>相关推荐</span></div><div class="relatedPosts-list"><div><a href="/zwyywz/2021/06/15/YOLOv5%E5%88%9D%E4%BD%93%E9%AA%8C/" title="【YOLOv5】初体验"><img class="cover" src="https://blog-1300216920.cos.ap-nanjing.myqcloud.com/yolo.jpg" alt="cover"><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2021-06-15</div><div class="title">【YOLOv5】初体验</div></div></a></div><div><a href="/zwyywz/2021/03/31/opencv%E5%AE%89%E8%A3%85%E6%95%99%E7%A8%8B/" title="【树莓派】OpenCV3源码方式安装教程"><img class="cover" src="https://blog-1300216920.cos.ap-nanjing.myqcloud.com/OpenCV.png" alt="cover"><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2021-03-31</div><div class="title">【树莓派】OpenCV3源码方式安装教程</div></div></a></div><div><a href="/zwyywz/2022/05/22/TensorRT%E6%95%99%E7%A8%8B/" title="TensorRT实战教程"><img class="cover" src="https://blog-1300216920.cos.ap-nanjing.myqcloud.com/FI-1.png" alt="cover"><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2022-05-22</div><div class="title">TensorRT实战教程</div></div></a></div><div><a href="/zwyywz/2023/04/15/%E5%9C%A8ubuntu%E4%B8%8A%E4%BB%8E0%E5%BC%80%E5%A7%8B%E9%85%8D%E7%BD%AE%E6%B7%B1%E5%BA%A6%E5%AD%A6%E4%B9%A0%E5%BC%80%E5%8F%91%E7%8E%AF%E5%A2%83/" title="在Ubuntu上从0开始配置深度学习开发环境"><img class="cover" src="https://cdn.educba.com/academy/wp-content/uploads/2020/01/Deep-Learning.jpg" alt="cover"><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2023-04-15</div><div class="title">在Ubuntu上从0开始配置深度学习开发环境</div></div></a></div><div><a href="/zwyywz/2021/06/15/%E5%9F%BA%E4%BA%8E%E6%9C%BA%E5%99%A8%E8%A7%86%E8%A7%89%E7%9A%84%E4%BB%BF%E7%94%9F%E6%9C%BA%E6%A2%B0%E6%89%8B%E6%8E%8C/" title="基于机器视觉的机械手掌"><img class="cover" src="https://blog-1300216920.cos.ap-nanjing.myqcloud.com/yolo.jpg" alt="cover"><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2021-06-15</div><div class="title">基于机器视觉的机械手掌</div></div></a></div></div></div></div><div class="aside-content" id="aside-content"><div class="sticky_layout"><div class="card-widget" id="card-toc"><div class="item-headline"><i class="fas fa-stream"></i><span>目录</span><span class="toc-percentage"></span></div><div class="toc-content"><ol class="toc"><li class="toc-item toc-level-1"><a class="toc-link" href="#Mac-M1-Pro-%E6%B7%B1%E5%BA%A6%E5%AD%A6%E4%B9%A0%E7%8E%AF%E5%A2%83%E6%90%AD%E5%BB%BA"><span class="toc-number">1.</span> <span class="toc-text">Mac M1 Pro 深度学习环境搭建</span></a><ol class="toc-child"><li class="toc-item toc-level-2"><a class="toc-link" href="#%E4%B8%80%E3%80%81%E5%89%8D%E8%A8%80"><span class="toc-number">1.1.</span> <span class="toc-text">一、前言</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E4%BA%8C%E3%80%81%E5%9F%BA%E7%A1%80%E7%8E%AF%E5%A2%83"><span class="toc-number">1.2.</span> <span class="toc-text">二、基础环境</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E4%B8%89%E3%80%81%E7%9B%B8%E5%85%B3%E7%9A%84%E7%AC%AC%E4%B8%89%E5%BA%93"><span class="toc-number">1.3.</span> <span class="toc-text">三、相关的第三库</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E5%9B%9B%E3%80%81%E5%BC%80%E5%8F%91%E5%B7%A5%E5%85%B7"><span class="toc-number">1.4.</span> <span class="toc-text">四、开发工具</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E4%BA%94%E3%80%81%E5%85%B6%E4%BB%96%E5%B7%A5%E5%85%B7"><span class="toc-number">1.5.</span> <span class="toc-text">五、其他工具</span></a></li></ol></li></ol></div></div></div></div></main><footer id="footer"><div id="footer-wrap"><div class="copyright">&copy;2020 - 2023 By Zhouwy</div><div class="framework-info"><span>框架 </span><a target="_blank" rel="noopener" href="https://hexo.io">Hexo</a><span class="footer-separator">|</span><span>主题 </span><a target="_blank" rel="noopener" href="https://github.com/jerryc127/hexo-theme-butterfly">Butterfly</a></div></div></footer></div><div id="rightside"><div id="rightside-config-hide"><button id="readmode" type="button" title="阅读模式"><i class="fas fa-book-open"></i></button><button id="translateLink" type="button" title="简繁转换">简</button><button id="darkmode" type="button" title="浅色和深色模式转换"><i class="fas fa-adjust"></i></button><button id="hide-aside-btn" type="button" title="单栏和双栏切换"><i class="fas fa-arrows-alt-h"></i></button></div><div id="rightside-config-show"><button id="rightside_config" type="button" title="设置"><i class="fas fa-cog fa-spin"></i></button><button class="close" id="mobile-toc-button" type="button" title="目录"><i class="fas fa-list-ul"></i></button><button id="go-up" type="button" title="回到顶部"><span class="scroll-percent"></span><i class="fas fa-arrow-up"></i></button></div></div><div><script src="/zwyywz/js/utils.js"></script><script src="/zwyywz/js/main.js"></script><script src="/zwyywz/js/tw_cn.js"></script><script src="https://cdn.jsdelivr.net/npm/@fancyapps/ui/dist/fancybox/fancybox.umd.min.js"></script><div class="js-pjax"></div><script async data-pjax src="//busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script></div></body></html>